﻿var Register = {
    btnRegisterClick: function () {
        $("#btnRegister").click(function () {
            $("span.loadingIcon").css("display", "inline-block");
            var lastName = $('input[name="LastName"]').val();
            var firstName = $('input[name="FirstName"]').val();
            var nickName = $('input[name="Nickname"]').val();
            var email = $('input[name="Email"]').val();
            var confirmEmail = $('input[name="ConfirmEmail"]').val();
            var password = $('input[name="Password"]').val();
            var confirmPassword = $('input[name="ConfirmPassword"]').val();
            var securityQuestionID = $('select[name="SecurityQuestion"]').val();
            var answer = $('input[name="Answer"]').val();
            var sex = $('select[name="Sex"]').val();
            var day = $('select[name="Day"]').val();
            var month = $('select[name="Month"]').val();
            var year = $('select[name="Year"]').val();
            var code = $('input[name=Code]').val();
            //            var challengeField = $('input[name="recaptcha_challenge_field"]').val();
            //            var responseField = $('input[name="recaptcha_response_field"]').val();
            $.ajax({
                url: "/Account/Register",
                type: "POST",
                data: {
                    "firstName": firstName, "lastName": lastName, "nickName": nickName, "email": email, "confirmEmail": confirmEmail,
                    "sex": sex, "password": password, "confirmPassword": confirmPassword, "securityQuestionID": securityQuestionID,
                    "answer": answer, "day": day, "month": month, "year": year, "code":code
                },
                cache: false,
                dataType: "html",
                success: function (data) {
                    $("span.loadingIcon").css("display", "none");
                    if (data == "0") {
                        $("div.box_error").css("display", "none");
                        $("div.box_success").html("Đăng ký thành công.");
                        $("div.box_success").slideDown(200);
                    }
                    else {
                        $("div.box_success").css("display", "none");
                        $("div.box_error").html(data);
                        $("div.box_error").slideDown(200);
                        Recaptcha.reload();
                        Recaptcha.focus_response_field();
                    }
                }
            });
        });
    },

    init: function () {
        Register.btnRegisterClick();
    }
}